/*
 * =====================================================================================
 * Copyright (C) 2023 Ingenic Semiconductor Co.,Ltd
 * All Rights Reserved
 *
 * Filename     : reg_base.h
 * Author       : Keven <keven.ywhan@ingenic.com>
 * Created      : 2024/06/06 11:15
 * Description  :
 *
 * =====================================================================================
 */

#ifndef __REG_BASE_H__
#define __REG_BASE_H__

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <core.h>

/* < Peripheral memory map */
#define CPM_BASE         0x10000000       /*!< Address base of CPM */
#define GPIO_BASE        0x10010000       /*!< Address base of GPIO Port A */
#define UART0_BASE       0x10030000       /*!< Address base of UART 0 */
#define UART1_BASE       0x10031000       /*!< Address base of UART 1 */
#define UART2_BASE       0x10032000       /*!< Address base of UART 2 */
#define I2C0_BASE        0x10050000       /*!< Address base of I2C0 */
#define I2C1_BASE        0x10051000       /*!< Address base of I2C1 */
#define I2C2_BASE        0x10052000       /*!< Address base of I2C2 */
#define INTC_BASE        0x12b00000       /*!< Address base of Core INTC1 */
#define DMAC_BASE        0x13420000       /*!< PDMA register base. */
#define PWM_BASE         0x13450000       /*!< PWM register base. */
#define CLINT_CTRL_BASE  0x12a00000
#define RISCV_BASE       0x12220000       /*!< RiscV CCU base address */


#define readb(addr)             (*(volatile unsigned char *)(addr))
#define readw(addr)             (*(volatile unsigned short *)(addr))
#define readl(addr)             (*(volatile unsigned int *)(addr))

#define writeb(b, addr)	        (*(volatile unsigned char *)(addr)) = (b)
#define writew(b, addr)	        (*(volatile unsigned short *)(addr)) = (b)
#define writel(b, addr)	        (*(volatile unsigned int *)(addr)) = (b)

#define set_bit(addr, b)        (writel((readl(addr) | (0x1<<b)), addr))
#define clear_bit(addr, b)      (writel((readl(addr) & ~(0x1<<b)), addr))

#endif /* __REG_BASE_H__ */
